package com.greendragon.persistence.domain; 

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


/** 
 * @author wulibin, exceptsky@gmail.com, 2011-9-8 下午11:02:32
 * 
 */
@Entity
@Table(name="user")
public class User implements Serializable{
	private static final long serialVersionUID = 761366881304893420L;

	private Long id;
	private String name;										//姓名
	private String password;									//密码
	private String email;										//邮件地址
	private String displayName;									//昵称
	private String website;										//网址
	private String  phone;           							//固定电话
    private String  cellphone;       							//手机
    private String  qq;											//QQ
    private String  securityQuestion; 							//安全问题
    private String  securityAnswer;  							//安全答案
    private String role;										//用户角色
	private String createdIp;									//创建IP	地址
	private String lastLoginIp;									//最后登入IP地址
    private Boolean gender;	 					         		//性别(男-true, 女-false)
    private Boolean block;										//账号是否冻结
    private Boolean active;										//是否账号已经激活
    private String activeCode;									//激活码
    private List<String> address;								//地址薄
	private Date createdAt;										//账号创建日期
	private Date lastLoginAt;									//最后登入日期
	private Resource avatar;									//头像
	private String gravatarHash;								//gavator头像hash
	
	public User() {}

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name="name", length=50)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name="password", length=50)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name="email", length=50)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name="displayName", length=50)
	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	@ElementCollection
	@CollectionTable(name = "userAddress",joinColumns=@JoinColumn(name="user_id"))
	@Column(name="address")
	public List<String> getAddress() {
		return address;
	}
	public void setAddress(List<String> address) {
		this.address = address;
	}

	@Column(name="gender", nullable=true)
	public Boolean getGender() {
		return gender;
	}

	public void setGender(Boolean gender) {
		this.gender = gender;
	}
	
	@Column(name="phone", length=15)
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	@Column(name="cellphone", length=15)
	public String getCellphone() {
		return cellphone;
	}

	public void setCellphone(String cellphone) {
		this.cellphone = cellphone;
	}
	
	@Column(name="qq", length=15)
	public String getQq() {
		return qq;
	}
	public void setQq(String qq) {
		this.qq = qq;
	}

	@Column(name="securityQuestion", length=100)
	public String getSecurityQuestion() {
		return securityQuestion;
	}
	public void setSecurityQuestion(String securityQuestion) {
		this.securityQuestion = securityQuestion;
	}
	
	@Column(name="securityAnswer", length=50)
	public String getSecurityAnswer() {
		return securityAnswer;
	}
	public void setSecurityAnswer(String securityAnswer) {
		this.securityAnswer = securityAnswer;
	}
	
	@Column(name="role", length=20)
	public String getRole() {
		return role;
	}
	public void setRole(String role) {
		this.role = role;
	}
	
	@Column(name="block", length=10)
	public Boolean getBlock() {
		return block;
	}
	public void setBlock(Boolean block) {
		this.block = block;
	}
	
	@Column(name="active")
	public Boolean getActive() {
		return active;
	}

	public void setActive(Boolean active) {
		this.active = active;
	}

	@Column(name="activeCode", length=64)
	public String getActiveCode() {
		return activeCode;
	}

	public void setActiveCode(String activeCode) {
		this.activeCode = activeCode;
	}

	@Column(name="createdIp", length=40)
	public String getCreatedIp() {
		return createdIp;
	}
	public void setCreatedIp(String createdIp) {
		this.createdIp = createdIp;
	}
	
	@Column(name="lastLoginIp", length=40)
	public String getLastLoginIp() {
		return lastLoginIp;
	}
	public void setLastLoginIp(String lastLoginIp) {
		this.lastLoginIp = lastLoginIp;
	}
	
	@Column(name="createdAt")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreatedAt() {
		return createdAt;
	}
	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}
	
	@Column(name="lastLoginAt")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getLastLoginAt() {
		return lastLoginAt;
	}
	public void setLastLoginAt(Date lastLoginAt) {
		this.lastLoginAt = lastLoginAt;
	}
	
	@Column(name="website", length=100)
	public String getWebsite() {
		return website;
	}
	public void setWebsite(String website) {
		this.website = website;
	}
	
	@ManyToOne
    @JoinColumn(name="avatar_id")
	public Resource getAvatar() {
		return avatar;
	}
	public void setAvatar(Resource avatar) {
		this.avatar = avatar;
	}

	@Column(name="gravatar_hash", length=40)
	public String getGravatarHash() {
		return gravatarHash;
	}

	public void setGravatarHash(String gravatarHash) {
		this.gravatarHash = gravatarHash;
	}
	
	
}
 